package net.dreamlu.utils;

import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Properties;

import com.jfinal.log.Logger;

/**
 * config util email: 596392912@qq.com site: http://www.dreamlu.net
 * 
 * @author chunmeng.lu
 */
public class ConfigUtil {
	protected static final Logger logger = Logger.getLogger(ConfigUtil.class);

	static final HashMap<String, String> config = new HashMap<String, String>();

	/**
	 * 读取配置文件，将配置文件分配到一个静态HashMap
	 * 
	 * @param properties
	 * @return
	 */
	public static void loadConfig(Properties properties) {
		for (Entry<Object, Object> entry : properties.entrySet()) {
			config.put(entry.getKey().toString(), entry.getValue().toString());
		}
	}

	public static final String get(String key) {
		String val = config.get(key);
		if (logger.isErrorEnabled()) {
			logger.error(String.format("key=[%s] value=[%s]", key, val));
		}
		return val;
	}

	public static Boolean getToBoolean(String key) {
		return Boolean.parseBoolean(config.get(key));
	}

	public static Long getToLong(String key) {
		return Long.parseLong(config.get(key));
	}
}
